#include <iostream>
#include <zlib/net/I_UnixNetProcessor.h>
#include <zlib/eventsystem/I_EventProcessor.h>
#include <unistd.h>

using namespace std;

extern UnixNetProcessor netProcessor;

class TestCont : public Continuation
{
public:
	TestCont()
	{
		SET_HANDLER(&TestCont::acceptEvent);
	}

	int acceptEvent(int event, void *data)
	{
		UnixNetVConnect *vc = (UnixNetVConnect *)data;
		if(event == NET_EVENT_ACCEPT){
			cout << "test cont:accept success:" << this_ethread() << endl;
			cout << "UnixNetVConnect:" << vc->fd << endl;
			MIOBuffer *buffer = new MIOBuffer;
			IOBufferReader *read = buffer->alloc_reader();
			vc->do_io_read(this, buffer, INT64_MAX);
		}else{
			cout << "accept faild" << endl;
		}
	}
};

int main()
{
	TestCont tcon;
	tcon.mutex = new_ProxyMutex();
	IpEntry bind_entry;
	bind_entry.init(AF_INET, "127.0.0.1", 8888);
	AcceptOptions opt;
	eventProcessor.start(1);
	//reuse ET_CALL Group Threads
	netProcessor.start(0);
	netProcessor.accept(&tcon, 1, bind_entry, opt);

	sleep(10000);
	return 0;
}
